package org.top10.parser;

import java.util.ArrayList;
import java.util.List;

import org.top10.collector.Collector;
import org.top10.entity.News;
import org.top10.entity.Video;
import org.top10.executor.ParseSource;
import org.top10.util.TOP10Global;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class BjnewsTask extends Task{
	private static final int webSiteID = TOP10Global.WEB_SITE_ID_BJnews;// 对应网站ID
	private static final String ENCoding = "gb2312";// 对应网站ID
	
	public BjnewsTask() {
		super(webSiteID, ENCoding);
	}

	public void loadParser() {
		PARSER.add(new BjnewsParser());
		
	}
	public static void main(String arg[]) throws Exception{
		new BjnewsParser().dealText(ENCoding);
	}
	
}
 class BjnewsParser extends TOPParserImpl {
	private static final String URL="http://www.bjnews.com.cn/ftp/app/news_top_3ed.php?len=50";
	private static final String TITLE="阅读排行";
	public BjnewsParser() {
		super(TITLE,TOP10Global.TYPE_News, URL);
	}

	public  List parse(ParseSource doc) throws Exception{
		NodeList body = doc.getDocSource().getElementsByTagName("a");
		List<News> list = new ArrayList<News>();
		for (int i = 0; i < body.getLength(); i++) {
			Node a=body.item(i);
			News v = new News();
			v.setRank(i+1);
			v.setName(a.getTextContent());
			v.setLinkUrl(getAttrValueByTag(a, "href"));
			System.out.println(v);
			list.add(v);
		}
		return list;
	}

	public  News build(Node node, int rank) throws Exception{
		return null;
	}



	
}
